- reflection = reference.reflection_name
- partial_name = "#{reference.class.type}_fields"
- attrs = { class: "nested-#{reflection.to_s.parameterize}" }
- cardinality = reference.cardinality
- list = f.object.send(reflection).select{|v| v.reference_name.to_s == reference.name.to_s}
- unless cardinality == '*'
  - attrs[:data] ||= {}
  - if cardinality.minimum?
    - attrs[:data][:association_insertion_minimum] = cardinality.minimum
    - while f.object.send(reflection).select{|v| v.reference_name.to_s == reference.name.to_s}.size < cardinality.minimum
      - f.object.send(reflection).new(reference_name: reference.name)
  - if cardinality.maximum?
    - attrs[:data][:association_insertion_maximum] = cardinality.maximum
- list = f.object.send(reflection).select{|v| v.reference_name.to_s == reference.name.to_s}
.nested-association.nested-parameters{attrs}
  - prefix = namespace + reflection.to_s

  = f.simple_fields_for(reflection, list) do |c|
    = render partial_name, f: c, reference: reference, namespace: prefix
  .links
    - if reference.display_status
      - if list.map(&:product).compact.blank?
        - invisible = 'display: none;'
      - else
        - miscibility = PhytosanitaryMiscibility.new(list.map(&:product)).validity
      %span.display-info{ style: invisible }
        %span= :"intervention_message_#{reference.display_status}".tl
        %span.status{ 'data-display-status': miscibility }
        %span.beta
          = :beta.tl
    = link_to_add_association :add_x.tl(x: reference.human_name), f, reflection, partial: partial_name, render_options: {locals: {thing: reflection, reference: reference, namespace: prefix}}, class: 'nested-add'
